package com.example.yaja.yaja.service;

import com.example.yaja.yaja.dao.TravelsMapper;
import com.example.yaja.yaja.entity.Travels;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Zero on 2017/12/5.
 */
@Service("travelsService")
public class TravelsServiceImpl implements TravelsService {

    @Autowired
    TravelsMapper travelsMapper;


    /**
     * 添加游记
     * @param travels
     * @return
     */
    @Override
    public int addTravels(Travels travels) {
        travelsMapper.insertSelective(travels);
        Integer travelsId=travels.getTravelsId();
        return travelsId;
    }

    /**
     * 通过Id查游记
     * @param travelsId
     * @return
     */
    @Override
    public Travels findTravelsById(Integer travelsId) {
        return travelsMapper.selectByPrimaryKey(travelsId);
    }

    /**
     * 更新游记
     * @param travels
     * @return
     */
    @Override
    public int updateTravels(Travels travels) {
        return travelsMapper.updateByPrimaryKeySelective(travels);
    }

    /**
     * 通过userId查询游记
     * @param userId
     * @return
     */
    @Override
    public List<Travels> findTravelsByUserId(Integer userId) {
        return travelsMapper.selectByUserId(userId);
    }

    /**
     * 审核游记
     * @param travelsId
     * @param state
     * @return
     */
    @Override
    public int updateState(Integer travelsId, Integer state) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("travelsId", travelsId);
        params.put("state", state);
        return travelsMapper.updateTravelState(params);
    }

    /**
     * 查询几条数据
     * @param startNumber
     * @param endNumber
     * @return
     */
    @Override
    public List<Travels> findTravelsByNumber(Integer startNumber, Integer endNumber) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("startNumber", startNumber);
        params.put("endNumber", endNumber);
        return travelsMapper.selectTravelsByNumber(params);
    }
}
